{% form_theme form '::fields2tab.html.twig' %}
<div class="contentwrapper">
    <div class="heading">
        <h3>Modifier Unite</h3>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <form id="form_unite" action="" {{ form_enctype(form) }} method="POST" class="form-horizontal seperator">
                {{ form_row(form.libelle) }}
                    {{ form_row(form.code) }}
                     {{form_row(form.chiffre_virgule,{'attr':{'onkeyup':'Test(this)'}})}}
                    {{ form_row(form._token) }}
                    
                    <div style="float: left;width: 90%" class="form-actions">
                        <button onclick="saveUnite()" class="btn btn-info" type="button">Enregistrer et retour vers liste</button>
                        <button onclick="listUnite()" class="btn" type="button">Retour vers liste</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
        $('#gds_articlebundle_unitetype_chiffre_virgule').spinner({
                                min: 0,
                                max: 10,
                                step: 1,
                                places: 0,
                                showOn: 'both'
                            });

                            function saveUnite() {
                                var data = $('#form_unite').serialize()
                                if ($('#form_unite').valid()) {
                                    $.ajax({
                                        type: 'post',
                                        url: '{{ path('gds_unite_edit') }}',
                                        data: data + '&id={{id}}',
                                        success: function(data) {
                                            $('#div_unite').html(data)
                                        }
                                    })
                                }
                            }
                            function listUnite() {
                                $.ajax({
                                    type: 'post',
                                    url: '{{ path('gds_unite_list') }}',
                                    success: function(data) {
                                        $('#div_unite').html(data)
                                    }
                                })
                            }
                            function Test(obj) {
                                var data = obj.value;
                                var d = data.substring(0, data.length - 1)
                                if (!TestVerif(data))
                                    obj.value = d
                            }
                            function TestVerif(decimal) {
                                var entier = "0123456789"
                                for (index_verif = 0; index_verif < decimal.length; index_verif++) {
                                    if (entier.indexOf(decimal[index_verif]) < 0) {
                                        return false
                                    }
                                    if(parseInt(decimal)>10)
                                        return false
                                }
                                return true
                            }
        </script>